/**
  ******************************************************************************
  * @file 扩展IO芯片管理
  * @brief 
  * @author helei
  * @version V1.0.0
  * @date 2022/12/12
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "expand_io.h"
#include "dev_tca9535.h"

/* Private defines -----------------------------------------------------------*/

/* Private Struct  -----------------------------------------------------------*/
dev_tca9535_t  m_expand_io[TCA9535_NUM] = 
{
    [TCA9535_1] = { .PIN_SCL = "B10",
                    .PIN_SDA = "B11",
                    .SLAVE_ADDR = 0x40,
                    .SAMPLE_DELAY = false,},

    [TCA9535_2] = { .PIN_SCL = "B10",
                    .PIN_SDA = "B11",
                    .SLAVE_ADDR = 0x42,
                    .SAMPLE_DELAY = false,},

};


/* Private enum    -----------------------------------------------------------*/

/* Private Variable  ---------------------------------------------------------*/
//Pointer

//Array

//Const

/* Private function prototypes -----------------------------------------------*/

/***********************************************************************************
 * @brief   功能说明：设置扩展IO输出引脚状态
 * ex:
 * @par     输入参数：TCA9535_TYPE type - 待控制的扩展IO模块索引值 
 *                    expand_io_status_e state - 输入输出状态控制：0-关闭，1-打开
 *                    uint16_t dev - 输出控制管脚
 *          输出参数：无
 * None
 * @retval  返回值：无
 **********************************************************************************/
void Expand_IO_SetState(TCA9535_TYPE type, expand_io_status_e state,uint16_t dev)
{
    if(type == TCA9535_1)
    {
        m_expand_io[TCA9535_1].WriteBit(&m_expand_io[TCA9535_1],state,dev);
    }
    else if(type == TCA9535_2)
    {
        m_expand_io[TCA9535_2].WriteBit(&m_expand_io[TCA9535_2],state,dev);
    }
}

/***********************************************************************************
 * @brief       查询扩展IO输入引脚状态
 * ex:
 * @par
 * None
 * @retval
 **********************************************************************************/
uint16_t Expand_IO_GetState(TCA9535_TYPE type)
{
    uint16_t data = 0;
	
    if(type == TCA9535_1)
    {
        data = m_expand_io[TCA9535_1].ReadData(&m_expand_io[TCA9535_1]);
    }
    else if(type == TCA9535_2)
    {
        data = m_expand_io[TCA9535_2].ReadData(&m_expand_io[TCA9535_2]);
    }

	return data;
}

/***********************************************************************************
* @brief      功能说明：LED所有控制管脚初始化设置为高电平
 * ex:
 * @par       输入参数：无
 *            输出参数：无
 * None
 * @retval    返回值：无
 **********************************************************************************/
void Expand_IO_Mode_Init(void)
{
	uint16_t out1 = 0xffff;
	//uint16_t in1 = FAN1_RD | FAN2_RD | FAN3_RD | FAN4_RD | FAN5_RD | FAN6_RD | FAN7_RD | FAN8_RD;
	//uint16_t out1 = LED_B1;
	uint16_t out2 = SWCON1 | SWCON2 | SWCON3 | SWCON4 | SWCON5 | SWCON6 | SWCON7 | SWCON8 | SWCON9 | SWCON10 | HEAT_CON1 | HEAT_CON2 | HEAT_CON3 | HEAT_CON4 | FAN9_CON;

	//初始化输出IO为高
	m_expand_io[TCA9535_1].ModeSetBit(&m_expand_io[TCA9535_1],TCA9535_OUTPUT,out1);
	Expand_IO_SetState(TCA9535_1,EXPAND_IO_OPEN,out1); 
	Expand_IO_SetState(TCA9535_1,EXPAND_IO_CLOSE,LED_G1); 
					
//	m_expand_io[TCA9535_2].ModeSetBit(&m_expand_io[TCA9535_2],TCA9535_OUTPUT,out2);
//	//初始化输出IO为低
//	Expand_IO_SetState(TCA9535_2,EXPAND_IO_CLOSE,out2);
}

/***********************************************************************************
 * @brief    功能说明：LED控制IO驱动端口、读写控制模块初始化
 * ex:
 * @par      输入参数：无
 *           输出参数：dev_tca9535_t  m_expand_io[TCA9535_NUM] - LED驱动端口、读写控制
 * None
 * @retval   返回值：初始化完成返回0，否则返回-1
 **********************************************************************************/
int Expand_IO_Init(void)
{
    if(Dev_Tca9535_Init(&m_expand_io[TCA9535_1]) < 0)
    {
        return -1;
    }

    if(Dev_Tca9535_Init(&m_expand_io[TCA9535_2]) < 0)
    {
        return -1;
    }

    return 0;
}

/******************* (C) COPYRIGHT 2020 CIQTEK helei *****END OF FILE****/
